/*
    Save or update test_release_lot table row based on TEST_REL_ID.
    Balaram, April 17, 2005
*/

ALTER  proc sp_save_or_update_test_release_lot (

@test_rel_id int,
@lot_id int,
@lot_number varchar(20),
@available_qty int,
@pulled_qty int,
@replaceable bit )

as
begin
	declare @row_count int
	select @row_count = count(*) from test_release_lot where test_rel_id = @test_rel_id and lotnumber = @lot_number

	if @row_count = 0 -- insert
	begin
		insert into test_release_lot ( test_rel_id, lotid, lotnumber, availqty, pulledqty, rplc )
		values( @test_rel_id, @lot_id, @lot_number, @available_qty, @pulled_qty, @replaceable )
	end

	else -- update
	begin
		update test_release_lot set availqty = @available_qty, pulledqty = @pulled_qty, rplc = @replaceable
		where test_rel_id = @test_rel_id and lotnumber = @lot_number
	end	

end